package com.hyt.it.ogt.kq.main.controller.admission;


import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.exception.annotation.ThrowsAdvice;
import com.hyt.it.ogt.kq.common.gov.config.swagger.ApiVersionConstant;
import com.hyt.it.ogt.kq.common.gov.constant.ResponseCode;
import com.hyt.it.ogt.kq.main.controller.base.BaseController;
import com.hyt.it.ogt.kq.service.admission.IAdmissionTicketTemplateService;
import com.hyt.it.ogt.kq.service.gov.model.dto.admission.AddOrUpdateAdmissionTemplateDTO;
import com.hyt.it.ogt.kq.service.gov.model.vo.admission.AdmissionStandardTemplateVO;
import com.hyt.it.ogt.kq.service.gov.model.vo.admission.AdmissionTemplateVO;
import com.hyt.it.ogt.kq.service.gov.model.vo.admission.TemplateConfigVO;
import com.hyt.log.annotation.Log;
import com.hyt.loginfo.model.Organization;
import com.hyt.loginfo.model.User;
import com.hyt.swagger.ApiVersion;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 准考证 前端控制器
 * </p>
 *
 * @author yanghuankun@talkweb.com.cn
 * @since 2023-1-13
 */
@RestController
@Api(tags = "232.准考证模板接口", value = "准考证模板接口")
@ApiSort(value = 232)
@RequestMapping("/kw/gov/admission/ticket/template")
@Slf4j
public class AdmissionTicketTemplateController extends BaseController {

    @Resource
    IAdmissionTicketTemplateService admissionTicketTemplateService;

    @ApiOperation(
            value = "32.1 获取标准模板列表",
            notes = "30000:成功;43140501:获取准考证模板异常",
            response = AdmissionStandardTemplateVO.class
    )
    @ApiOperationSort(value = 1)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证模板管理", business = "获取标准模板列表")
    @ThrowsAdvice(code = 43140501, print = "获取准考证模板异常")
    @GetMapping("/standardList")
    public ApiResponse<List<AdmissionStandardTemplateVO>> standardList() {
        return ApiResponse.<List<AdmissionStandardTemplateVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(admissionTicketTemplateService.standardList())
                .build();
    }

    @ApiOperation(
            value = "32.2 新增和编辑时获取准考证可以使用的模板",
            notes = "20000:成功; 43140501:获取准考证可以使用的模板异常"
    )
    @ApiOperationSort(value = 2)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证模板管理", business = "新增和编辑时获取准考证可以使用的模板")
    @ThrowsAdvice(code = 43140501, print = "获取准考证可以使用的模板异常")
    @GetMapping("/admissionTicketTemplate")
    public ApiResponse<List<AdmissionTemplateVO>> admissionTicketTemplate(
            @ApiParam(name = "admissionTicketInfoId", value = "准考证任务的id，创建时不需要传递，编辑时需要传递")
            @RequestParam(required = false) String admissionTicketInfoId
    ) {
        String officeId = getOfficeId();
        String deptId = getDeptId();
        return ApiResponse.<List<AdmissionTemplateVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(admissionTicketTemplateService.admissionTicketTemplate(officeId, deptId, admissionTicketInfoId))
                .build();
    }

    @ApiOperation(
            value = "32.3 更新自定义模板",
            notes = "20000:成功; 43320301:更新自定义模板异常"
    )
    @ApiOperationSort(value = 3)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证模板管理", business = "更新自定义模板")
    @ThrowsAdvice(code = 43320301, print = "更新自定义模板异常")
    @PutMapping
    public ApiResponse<Void> update(@RequestBody AddOrUpdateAdmissionTemplateDTO addOrUpdateAdmissionTemplateDTO) {
        User user = getUser();
        Organization deptInfo = getDeptInfo();
        admissionTicketTemplateService.update(user, deptInfo, addOrUpdateAdmissionTemplateDTO);
        return ApiResponse.<Void>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .build();
    }

    @ApiOperation(
            value = "32.4 获取模板详情",
            notes = "20000:成功; 43320401:获取模板详情异常"
    )
    @ApiOperationSort(value = 4)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证模板管理", business = "获取模板详情")
    @ThrowsAdvice(code = 43320401, print = "获取准考证任务模板失败")
    @GetMapping("/byAdmissionId")
    public ApiResponse<AdmissionTemplateVO> byAdmissionId(
            @ApiParam(value = "准考证id")
            @RequestParam String admissionId) {
        return ApiResponse.<AdmissionTemplateVO>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(admissionTicketTemplateService.byAdmissionId(admissionId))
                .build();
    }

    @ApiOperation(
            value = "32.5 获取模板可以选择的配置",
            notes = "20000:成功; 43320501:获取可以选择的配置异常"
    )
    @ApiOperationSort(value = 5)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证模板管理", business = "获取模板可以选择的配置")
    @ThrowsAdvice(code = 43320501, print = "获取可以选择的配置异常")
    @GetMapping("/listTemplateConfig")
    public ApiResponse<List<TemplateConfigVO>> listTemplateConfig(
            @ApiParam(value = "准考证id")
            @RequestParam String admissionId) {
        return ApiResponse.<List<TemplateConfigVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(admissionTicketTemplateService.listTemplateConfig(admissionId))
                .build();
    }

}
